<template>
	<u-popup v-model="show" mode="center" border-radius="16">
		<view class="control-pop-content">
			<view class="header-wrap">
				<text class="header-title">请选择</text>
				<image @click="handleClose" src="/static/img/close_icon.png" mode="aspectFill" class="close-icon">
				</image>
			</view>
			<view class="btn-box">
				<view class="btn-item" @click="handleControl(1)">
					<image src="/static/img/guan_ji.png" class="btn-icon" mode="aspectFill"></image>
					<text class="btn-title">关机</text>
				</view>
				<view class="btn-item" @click="handleControl(2)">
					<image src="/static/img/chong_xi.png" class="btn-icon" mode="aspectFill"></image>
					<text class="btn-title">冲洗</text>
				</view>
			</view>
		</view>
	</u-popup>
</template>

<script>
	import { request, showLoading, toast } from "@/utils/tool.js"
	export default {
		data() {
			return {
				show: false,
				shebei_id: ""
			}
		},
		methods: {
			handleControl(type) {
				const { shebei_id } = this
				if (!shebei_id) return toast({ title: "未选择设备" })
				const typeText = type === 1 ? '关机' : '冲洗';
				uni.showModal({
					title: '确认信息',
					content: '您确认要执行' + typeText + '吗?',
					success: async ev => {
						if (ev.cancel) return
						const hide = showLoading("请稍等")
						const resp = await request({
							url: "/shebei/zhiling",
							method: "POST",
							data: {
								shebei_id,
								type
							}
						}).catch(hide)
						if (resp.code !== 1) return hide()
						this.shebei_id = ""
						hide()
						toast({ title: typeText + "成功", icon: "succes" })
						this.handleClose()
					}
				})
			},
			open(shebei_id) {
				this.show = true
				this.shebei_id = shebei_id
			},
			handleClose() {
				this.show = false
			}
		},
	}
</script>

<style lang="scss" scoped>
	.control-pop-content {
		padding: 28rpx 22rpx 64rpx;
		width: 668rpx;
		box-sizing: border-box;

		.btn-box {
			display: flex;
			align-items: center;
			margin-top: 42rpx;

			.btn-item {
				flex: 1;
				height: 122rpx;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				border: 2rpx solid #3361F0;
				display: flex;
				align-items: center;
				box-sizing: border-box;
				position: relative;
				padding-left: 24rpx;

				.btn-icon {
					width: 50rpx;
					height: 50rpx;
				}

				.btn-title {
					font-weight: 400;
					font-size: 28rpx;
					color: #000000;
					line-height: 40rpx;
					margin-left: 20rpx;
				}

				&:first-child {
					margin-right: 58rpx;
				}
			}
		}


		.close-icon {
			width: 40rpx;
			height: 40rpx;
			position: absolute;
			top: 50%;
			right: 16rpx;
			transform: translateY(-50%);
		}

		.header-wrap {
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;

		}

		.header-title {
			font-weight: 400;
			font-size: 32rpx;
			color: #000000;
			letter-spacing: 1px;
			line-height: 44rpx;
			text-align: center;
		}


	}
</style>